package calao.util;

import java.util.Vector;

public class Cursors 
{

	static public <T> T[] toArray(Cursor<T> cursor, Class<T> type)
	{
		return toArray(cursor, type, null);
	}
	
	static public <T> T[] toArray(Cursor<T> cursor, Class<T> type, Filter<T> filter)
	{
		Vector<T> vector = new Vector<T>();
		try {
			while (cursor.next()) {
				if (filter==null || filter.passes(cursor.get())) vector.add(cursor.get());
			}
			return Arrays.toArray(vector, type);
		}
		finally {
			cursor.close();
		}
	}
	
}
